--
-- Description: Script to copy the records from the 
-- staging eventhits table to the eventhits table.
-- Date created: 6 May 2008
--

set ANSI_NULLS on
set QUOTED_IDENTIFIER on
go

--
-- drop the stored procedure if it exists and recreate it.
--
if exists
(
	select * 
	from sys.objects
	where object_id = object_id(N'[commitEventHits_sp]')
	and type in (N'P', N'PC')
)
begin
    drop procedure [dbo].[commitEventHits_sp]
end
go

create procedure [dbo].[commitEventHits_sp]
(
	@Commit bit
)
as
begin
	--
	-- copy the records from the stage event hits to the event hits table.
	--
	insert into [dbo].[EventHits]
	(
		[EventID]
		, [EventTypeID]
		, [DateCreated]
		, [DateModified]
		, [TotalHits]
		, [OperatingSystemID]
		, [LocaleID]
	)
	select 
		EventID
		, EventTypeID
		, DateCreated
		, DateModified
		, TotalHits
		, OperatingSystemID
		, LocaleID
	from [dbo].[StageEventHits]

	--
	-- truncate the stage event hits table
	--
	truncate table [dbo].[StageEventHits]
end
go

set ansi_nulls off
go
set quoted_identifier off
go
